package com.own.core.object;

import java.io.Serializable;
import java.lang.reflect.Field;

import javax.persistence.Transient;

import org.apache.wicket.IClusterable;

import com.own.core.util.OwnDate;

public abstract class Dao implements IClusterable ,Serializable{

	
	private boolean delete;
	private boolean systemCreator;
//	private Long createdBy;
//	private OwnDate createdData;
	
	public String toString() {
		StringBuilder str = new StringBuilder();
		str.append("[");
		Field[] fields = this.getClass().getDeclaredFields();
		for (Field field : fields) {
			try {
				field.setAccessible(true);
				Class cls = field.getType();
				if (!(cls.isPrimitive() || (cls.getName().indexOf("java.lang") > -1))) {
					continue;
				}

				Object obj = field.get(this);
				// if (obj instanceof Dao) {
				// Dao dao = (Dao) obj;
				// str.append(field.getName() + " =\"" + dao.toSimpleString()
				// + "\",");
				// }

				str.append(field.getName() + " =\"" + obj.toString() + "\",");
			} catch (Exception e) {
				// e.printStackTrace();
				System.out.println();
			}

		}
		str.deleteCharAt(str.length() - 1).append("]");
		return str.toString();
	}

	public String toSimpleString() {
		StringBuilder str = new StringBuilder();
		str.append("[");
		Field[] fields = this.getClass().getDeclaredFields();
		for (Field field : fields) {
			try {
				field.setAccessible(true);
				Object obj = field.get(this);
				if (obj instanceof Dao) {
					continue;
				}

				str.append(field.getName() + " =\"" + obj.toString() + "\",");
			} catch (Exception e) {
			}

		}
		str.deleteCharAt(str.length() - 1).append("]");
		return str.toString();
	}

	@Transient
	public abstract String getName();
	

	public  void delete(){};

	public abstract long getId();

	@Override
	public boolean equals(Object obj) {

		if (obj.getClass().toString().equals(this.getClass().toString())) {
			Dao dao = (Dao) obj;
			if (this.getId() == dao.getId()) {

				return true;
			}

		}

		return false;

	}

	@Override
	public int hashCode() {
		return (int) getId();

	}

	public boolean isDelete() {
		return delete;
	}

	public void setDelete(boolean delete) {
		this.delete = delete;
	};
}
